//
//  UIButton+Extension.swift
//  Weibo10
//
//  Created by Leon on 15/10/14.
//  Copyright © 2015年 Leon. All rights reserved.
//

import UIKit

extension UIButton {
    
    /// - 备注：如果图像名称使用 "" 会抱错误 CUICatalog: Invalid asset name supplied:
    convenience init(imageName: String, backImageName: String?) {
        
        self.init()
        
        setImage(UIImage(named: imageName), forState: .Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        
        if let backImageName = backImageName {
            setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
            setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: .Highlighted)
        }
        sizeToFit()
    }
    
    convenience init(title: String, titleColor: UIColor, imageName: String) {
        
        self.init()
        
        setTitle(title, forState: .Normal)
        setTitleColor(titleColor, forState: .Normal)
        setBackgroundImage(UIImage(named:imageName), forState: .Normal)
    }
    
    convenience init(title: String, imageName: String, backImageName: String, color: UIColor = UIColor.darkGrayColor(), fontSize: CGFloat = 15) {
        
        self.init()
        
        setTitle(title, forState: .Normal)
        setTitleColor(color, forState: .Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        setImage(UIImage(named: imageName), forState: .Normal)
        setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: .Highlighted)
    }
}


